1  Save scTCR and bulkTCR colorschemes

1.1 Set up workspace

# Libraries
library(Seurat)
Loading required package: SeuratObject
Loading required package: sp

Attaching package: 'SeuratObject'
The following objects are masked from 'package:base':

    intersect, t
library(colorblindr)
Loading required package: colorspace
Loading required package: ggplot2
library(RColorBrewer)
library(paletteer)
library(dplyr)

Attaching package: 'dplyr'
The following objects are masked from 'package:stats':

    filter, lag
The following objects are masked from 'package:base':

    intersect, setdiff, setequal, union
library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ forcats   1.0.0     ✔ stringr   1.5.1
✔ lubridate 1.9.4     ✔ tibble    3.2.1
✔ purrr     1.0.4     ✔ tidyr     1.3.1
✔ readr     2.1.5     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors

1.2 Assign custom color scheme

projectils_fill <- scale_fill_manual(values = c("CD4.NaiveLike" = "#F7FBFF", "CD4.Memory" = "#DEEBF7", "CD4.Tfh" = "#C6DBEF", "CD4.Th17" = "#9ECAE1", "CD4.CTL_GNLY" = "#6BAED6", "CD4.CTL_EOMES" = "#4292C6", "CD4.CTL_Exh" = "#2171B5", "CD4.Treg" = "#084594", "CD8.NaiveLike" = "#FEE5D9", "CD8.MAIT" = "#FCBBA1", "CD8.CM" = "#FC9272", "CD8.EM" = "#FB6A4A", "CD8.TEMRA" = "#EF3B2C", "CD8.TPEX" = "#CB181D", "CD8.TEX" = "#99000D"))

projectils_color <- scale_color_manual(values = c("CD4.NaiveLike" = "#F7FBFF", "CD4.Memory" = "#DEEBF7", "CD4.Tfh" = "#C6DBEF", "CD4.Th17" = "#9ECAE1", "CD4.CTL_GNLY" = "#6BAED6", "CD4.CTL_EOMES" = "#4292C6", "CD4.CTL_Exh" = "#2171B5", "CD4.Treg" = "#084594", "CD8.NaiveLike" = "#FEE5D9", "CD8.MAIT" = "#FCBBA1", "CD8.CM" = "#FC9272", "CD8.EM" = "#FB6A4A", "CD8.TEMRA" = "#EF3B2C", "CD8.TPEX" = "#CB181D", "CD8.TEX" = "#99000D"))

1.3 Relevel functional.cluster factor before plotting

projectils_celltypes <- c("CD4.NaiveLike", "CD4.Memory", "CD4.Tfh", "CD4.Th17", "CD4.CTL_GNLY", "CD4.CTL_EOMES", "CD4.CTL_Exh", "CD4.Treg", "CD8.NaiveLike","CD8.MAIT", "CD8.CM", "CD8.EM", "CD8.TEMRA", "CD8.TPEX", "CD8.TEX")

projectils_celltypes <- factor(projectils_celltypes, levels = c("CD4.NaiveLike", "CD4.Memory", "CD4.Tfh", "CD4.Th17", "CD4.CTL_GNLY", "CD4.CTL_EOMES", "CD4.CTL_Exh", "CD4.Treg", "CD8.NaiveLike","CD8.MAIT", "CD8.CM", "CD8.EM", "CD8.TEMRA", "CD8.TPEX", "CD8.TEX"))

1.4 Check plots are working

# A plot with all the data
p <- projectils_celltypes %>%
  as.data.frame(functional.cluster = projectils_celltypes) %>%
  ggplot(aes(x = 1, fill = projectils_celltypes)) + 
  geom_bar() + 
  projectils_fill
p

1.5 Check colors for colorblindness

cvd_grid(p)

1.6 Save color and fill environment variables

saveRDS(projectils_fill, "Part0_ProjecTILs_Fill.rds")
saveRDS(projectils_color, "Part0_ProjecTILs_Color.rds")

1.7 Load ifng, tumor and skin single cell data

patients <- c("P101", "P103", "P104", "P105", "P106", "P108", "P109", "P110", "P111")

1.8 Create factors

patients <- data.frame(Patient = patients) %>%
  mutate(Patient = factor(Patient))

1.9 Assign custom color scheme

colors <- c( "#59A14F",  "#B07AA1FF", "#76B7B2FF", "#FBB258FF", "#DC050C", "#F6AAC9FF", "#5ca2e5", "#615ebf", "#826250") 

names(colors) <- levels(patients$Patient)
patient_fill <- scale_fill_manual(values = colors)
patient_color <- scale_color_manual(values = colors)

1.10 Check plots are working

# A plot with all the data
p <- ggplot(patients, aes(x = 1,fill = Patient)) + 
  geom_bar() + 
  patient_fill
p + ggtitle("BulkTCR Patients")

# A plot with the single cell patients: P101, P103, P104 and P108
p2 <- patients[c(1,2,3,6), 1, drop = FALSE] %>%
  ggplot(aes(x = 1,fill = Patient)) + 
  geom_bar() + 
  patient_fill
p2 + ggtitle("scRNA Patients")

1.11 Check colors for colorblindness

cvd_grid(p)

cvd_grid(p2)

1.12 Save color and fill environment variables

saveRDS(patient_fill, "Part0_Patient_Fill.rds")
saveRDS(patient_color, "Part0_Patient_Color.rds")

1.13 Get session info

sessionInfo()
R version 4.3.2 (2023-10-31)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Rocky Linux 8.10 (Green Obsidian)

Matrix products: default
BLAS/LAPACK: /usr/lib64/libopenblasp-r0.3.15.so;  LAPACK version 3.9.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

time zone: America/New_York
tzcode source: system (glibc)

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] lubridate_1.9.4    forcats_1.0.0      stringr_1.5.1      purrr_1.0.4       
 [5] readr_2.1.5        tidyr_1.3.1        tibble_3.2.1       tidyverse_2.0.0   
 [9] dplyr_1.1.4        paletteer_1.6.0    RColorBrewer_1.1-3 colorblindr_0.1.0 
[13] ggplot2_3.5.1      colorspace_2.1-1   Seurat_5.1.0       SeuratObject_5.0.2
[17] sp_2.2-0          

loaded via a namespace (and not attached):
  [1] deldir_2.0-4           pbapply_1.7-2          gridExtra_2.3         
  [4] rematch2_2.1.2         rlang_1.1.5            magrittr_2.0.3        
  [7] RcppAnnoy_0.0.22       spatstat.geom_3.3-2    matrixStats_1.5.0     
 [10] ggridges_0.5.6         compiler_4.3.2         png_0.1-8             
 [13] vctrs_0.6.5            reshape2_1.4.4         pkgconfig_2.0.3       
 [16] fastmap_1.2.0          labeling_0.4.3         promises_1.3.2        
 [19] rmarkdown_2.29         tzdb_0.5.0             xfun_0.50             
 [22] jsonlite_1.8.9         goftest_1.2-3          later_1.4.1           
 [25] spatstat.utils_3.1-0   irlba_2.3.5.1          parallel_4.3.2        
 [28] cluster_2.1.8.1        R6_2.6.1               ica_1.0-3             
 [31] stringi_1.8.4          spatstat.data_3.1-2    reticulate_1.42.0     
 [34] parallelly_1.41.0      spatstat.univar_3.0-0  lmtest_0.9-40         
 [37] scattermore_1.2        Rcpp_1.0.14            knitr_1.49            
 [40] tensor_1.5             future.apply_1.11.3    zoo_1.8-13            
 [43] sctransform_0.4.1      timechange_0.3.0       httpuv_1.6.15         
 [46] Matrix_1.6-5           splines_4.3.2          igraph_2.0.3          
 [49] tidyselect_1.2.1       rstudioapi_0.17.1      abind_1.4-8           
 [52] spatstat.random_3.3-1  codetools_0.2-20       miniUI_0.1.1.1        
 [55] spatstat.explore_3.3-2 listenv_0.9.1          lattice_0.22-7        
 [58] plyr_1.8.9             withr_3.0.2            shiny_1.9.1           
 [61] ROCR_1.0-11            evaluate_1.0.1         Rtsne_0.17            
 [64] future_1.34.0          fastDummies_1.7.5      survival_3.8-3        
 [67] polyclip_1.10-7        fitdistrplus_1.2-2     pillar_1.10.1         
 [70] KernSmooth_2.23-26     plotly_4.10.4          generics_0.1.3        
 [73] RcppHNSW_0.6.0         hms_1.1.3              munsell_0.5.1         
 [76] scales_1.3.0           globals_0.16.3         xtable_1.8-4          
 [79] glue_1.8.0             lazyeval_0.2.2         tools_4.3.2           
 [82] data.table_1.15.4      RSpectra_0.16-2        RANN_2.6.2            
 [85] leiden_0.4.3.1         dotCall64_1.2          cowplot_1.1.3         
 [88] grid_4.3.2             nlme_3.1-168           patchwork_1.3.0       
 [91] cli_3.6.3              spatstat.sparse_3.1-0  spam_2.11-1           
 [94] viridisLite_0.4.2      uwot_0.2.3             gtable_0.3.6          
 [97] digest_0.6.37          progressr_0.15.1       ggrepel_0.9.5         
[100] htmlwidgets_1.6.4      farver_2.1.2           htmltools_0.5.8.1     
[103] lifecycle_1.0.4        httr_1.4.7             mime_0.13             
[106] MASS_7.3-60.0.1